package com.ming.yygh.order.api;

import com.ming.yygh.common.result.Result;
import com.ming.yygh.model.order.OrderInfo;
import com.ming.yygh.order.service.OrderService;
import com.ming.yygh.vo.order.OrderCountQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Light
 * @date 2021/12/22 18:22
 */
@RestController
@RequestMapping("api/order/orderInfo")
public class OrderApiController {

    @Resource
    private OrderService orderService;

    @ApiOperation(value = "生成挂号订单")
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result<String> saveOrders(@PathVariable(value = "scheduleId") String scheduleId,
                                     @PathVariable(value = "patientId") String patientId) {
        String orderId = orderService.saveOrder(scheduleId, patientId);
        return Result.ok(orderId);
    }

    @ApiOperation(value = "根据订单id查询订单详情")
    @GetMapping("/auth/getOrders/{orderId}")
    public Result<OrderInfo> getOrders(@PathVariable(value = "orderId") String orderId) {
        OrderInfo orderInfo = orderService.getOrder(orderId);
        return Result.ok(orderInfo);
    }

    @ApiOperation(value = "取消预约")
    @GetMapping("auth/cancelOrder/{orderId}")
    public Result<Boolean> cancelOrder(@PathVariable(value = "orderId") String orderId) {
        Boolean isOrder = orderService.cancelOrder(orderId);
        return Result.ok(isOrder);
    }

    @ApiOperation(value = "获取订单统计的数量")
    @PostMapping("/inner/getCountMap")
    public Result<Map<String, Object>> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        return Result.ok(orderService.getCountMap(orderCountQueryVo));
    }

}
